package cool.tianyou.blue.bird.factory;

import android.content.Context;
import android.graphics.drawable.Icon;
import android.os.Build;

import androidx.annotation.RequiresApi;

import java.text.SimpleDateFormat;
import java.util.Date;

import cool.tianyou.blue.bird.R;
import cool.tianyou.blue.bird.model.CommonMessage;
import cool.tianyou.blue.bird.model.NotificationData;

public class MessageFactory {

    /**
     * 创建电量消息
     *
     * @param level      电量
     * @param isCharging 充电状态
     * @return
     */
    public static CommonMessage batteryMessage(Integer level, Boolean isCharging) {
        CommonMessage message = new CommonMessage();
        message.setNotification(new NotificationData(null, "电量变更通知", "电量数据", ""));
        message.setType("BATTERY_LEVEL");
        message.genUuid();
        message.setLogSaveToLogList(false);
        message.setTime(new Date()).putEncryptedData("level", level).putEncryptedData("status", isCharging);
        return message;

    }


    @RequiresApi(api = Build.VERSION_CODES.M)
    public static CommonMessage smsMessage(String address, Date time, String content, Context context) {
        CommonMessage message = new CommonMessage();
        message.setNotification(new NotificationData(Icon.createWithResource(context, R.mipmap.sms), address, content, ""));
        message.setType("SMS");
        message.genUuid();
        message.setTime(time).putEncryptedData("address", address).putEncryptedData("content", content);
        return message;
    }


    public static CommonMessage notificationMessage(Icon largeIcon, String base64, String notificationTitle, String notificationText, String notificationPkg) {
        CommonMessage commonMessage = new CommonMessage();
        NotificationData notificationData =
                new NotificationData(largeIcon, notificationTitle, notificationText, notificationPkg);
        Date now = new Date();
        commonMessage.setTime(now);
        commonMessage.genUuid();
        commonMessage.setType("PHONE_NOTIFICATION");
        commonMessage.setNotification(notificationData).setTime(now)
                .putEncryptedData("title", notificationTitle)
                .putEncryptedData("content", notificationText)
                .putEncryptedData("pkg", notificationPkg)
                .putEncryptedData("time", new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(now))
                .putNonEncryptedData("icon", base64);
        return commonMessage;

    }

}
